import matplotlib.pyplot as plt
import streamlit as st

fig, (ax1, ax2) = plt.subplots(1, 2)
ax1.plot([1, 2, 3, 4], [1, 2, 3, 4])
ax2.bar([1, 2, 3, 4], [1, 2, 3, 4])
st.pyplot(fig, use_container_width=False)


import altair as alt
import pandas as pd

data = pd.DataFrame(
    {
        "name": ["张三", "李四", "王五", "赵六", "孙七"],
        "age": [18, 19, 20, 21, 22],
        "sex": ["男", "女", "男", "女", "男"],
        "city": ["北京", "上海", "广州", "深圳", "杭州"],
    }
)
chart = alt.Chart(data).mark_bar().encode(
    x="name",
    y="age",
    color="sex",
    tooltip=["name", "age", "sex", "city"],
    # 这段代码定义了一个tooltip列表，用于设置鼠标悬停时显示的提示信息。
    # 列表中包含四个字段：姓名、年龄、性别和城市，当用户将鼠标悬停在相关元素上时，会显示这些个人信息的提示框。
)
st.altair_chart(chart, use_container_width=True)


import plotly.express as px

px_fig = px.bar(data, x="name", y="age", color="sex", hover_data=["city"])  # hover_data=["city"] 设置鼠标悬停时显示城市信息
st.plotly_chart(px_fig, use_container_width=True)
